package com.example.oaidtest2;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.example.oaidtest2.constant.Constant;
import com.example.oaidtest2.utils.DeviceManager;

import cn.jiguang.jgssp.ADJgSdk;
import cn.jiguang.jgssp.config.ADJgInitConfig;
import cn.jiguang.jgssp.config.CustomDeviceInfoController;
import cn.jiguang.jgssp.util.ADJgLogUtil;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ADJgSdk.getInstance().init(getApplicationContext(), new ADJgInitConfig.Builder()
            .appId(Constant.APP_ID)
            .debug(true)
            .setCustomDeviceInfoController(new CustomDeviceInfoController() {
                @Override
                public String getOaid() {
                    /**
                     * OAID初始化和本SDK初始化没有先后顺序关系。
                     * SDK每次需要Oaid的时候，都会调用此方法，
                     * 只需要保证Oaid_SDK返回的字符串在DeviceManager单例对象中正常保存和获取即可
                     */
                    return DeviceManager.getInstance().getOaid();
                }

                @Override
                public String getVaid() {
                    return DeviceManager.getInstance().getVaid();
                }
            })
            .build());

        findViewById(R.id.btnTestOaid).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String oaid = ADJgSdk.getInstance().getOAID();
                Toast.makeText(MainActivity.this, "SDK获取到oaid" + oaid, Toast.LENGTH_LONG).show();
                ADJgLogUtil.d("MainActivity OAID : " + oaid);
            }
        });

    }
}
